package com.vogue.supplymall.account;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.vogue.configs.startup.SpringContext;
import com.vogue.configs.startup.SpringStart;
import com.vogue.gear.memory.provider.annotation.MemorySchemeP2P;
import com.vogue.ssm.controller.help.ErrorMsg;
import com.vogue.ssm.database.annotation.ScanEntity;
import com.vogue.ssm.database.entity.SnowflakeIdWorker;

@SpringBootApplication
@EnableTransactionManagement
@EnableAsync
@MemorySchemeP2P
@ScanEntity(scanPack = { "com.vogue.supplymall.account.domain.model" })
@Import(SpringContext.class)
public class AdminAccountApplication {

	public static void main(String[] args){
        Map<String,String> mapargs=transargs(args);
        if(mapargs.size()>0){
            String s1=mapargs.get("serno");//所在服务器编号
            if(StringUtils.isNotEmpty(s1)){
                SnowflakeIdWorker.serno=Integer.parseInt(s1);
            }
            s1=mapargs.get("dsno");//同一服务器中服务的编号
            if(StringUtils.isNotEmpty(s1)){
                SnowflakeIdWorker.dsno=Integer.parseInt(s1);
            }
        }
        SpringStart.run(AdminAccountApplication.class,args);
        ErrorMsg.deftemp="%s";
    }

    private static Map<String,String> transargs(String[] args){
        Map<String,String> mapargs=new HashMap<String, String>();
        if(args!=null){
            for (String arg:args){
                if (arg.startsWith("--")){
                    int pos=arg.indexOf("=");
                    if(pos>0){
                        mapargs.put(arg.substring(2,pos),arg.substring(pos+1));
                    }
                }
            }
        }
        return mapargs;
    }
}
